<template>
	<view>
		<!-- 自定义导航 -->
		<news-nav-bar :tabBars="tabBars" :tabIndex="tabIndex" @change-tab="tabtap"></news-nav-bar>

		<view class="uni-tab-bar">
			<swiper :style="{height:swiperHeight+'px'}" :current="tabIndex" @change="swiperChange">
				<!-- 关注 -->
				<swiper-item>
					<scroll-view scroll-y class="list" @scrolltolower="loadmore()">
						<!-- 列表 -->
						<block v-for="(item, index) in guanzhu.list" :key="index">
							<commonList :item="item" :index="index"></commonList>
						</block>
						<!-- 上拉加载 -->
						<loadMore :loadtext="guanzhu.loadtext"></loadMore>
					</scroll-view>
				</swiper-item>
				<!-- 话题 -->
				<swiper-item>
					<scroll-view scroll-y class="list">
						<!-- 搜索框 -->
						<view class="search-input">
							<input class="uni-input" type="text" placeholder-class="u-f-ajc icon iconfont icon-sousuo topic-search"
							 placeholder="搜索内容" />
						</view>
						<!-- 轮播图 -->
						<swiper class="topic-swiper" :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000">
							<block v-for="(item, index) in topic.swiper" :key="index">
								<swiper-item>
									<image :src="item.src" mode="widthFix"></image>
								</swiper-item>
							</block>
						</swiper>
						<!-- 热门分类 -->
						<topic-nav :nav="topic.nav"></topic-nav>
						<!-- 最近更新 -->
						<view class="topic-new ">
							<view>最近更新</view>
							<block v-for="(item,index) in topic.list" :key="index">
								<topic-new-list :item="item" :index="index"></topic-new-list>
							</block>
						</view>
					</scroll-view>
				</swiper-item>
			</swiper>
		</view>
	</view>
</template>

<script>
	import commonList from '../../components/common/common-list.vue';
	import newsNavBar from '../../components/news/news-nav-bar.vue';
	import topicNav from '../../components/news/topic-nav.vue';
	import topicNewList from '../../components/news/topic-new-list.vue';
	import loadMore from '../../components/common/load-more.vue';
	export default {
		components: {
			commonList,
			newsNavBar,
			loadMore,
			topicNav,
			topicNewList
		},
		data() {
			return {
				swiperHeight: 500,
				tabBars: [{
						name: "关注",
						id: "guanzhu"
					},
					{
						name: "话题",
						id: "topic"
					}
				],
				tabIndex: 0,
				guanzhu: {
					loadtext: "上拉加载更多",
					list: [{
							userpic: "../../static/demo/userpic/1.jpg",
							username: "昵称",
							sex: 1, //0-男 1-女
							age: 25,
							isguanzhu: false,
							title: "我是标题",
							type: "text", //img:图文 video: 视频
							titlepic: "",
							infoNum: {
								index: 1, //0 - 没有操作, 1 - 顶, 2 - 踩
								dingNum: 11,
								caiNum: 12,
							},
							commentNum: 12,
							shareNum: 123
						},
						{
							userpic: "../../static/demo/userpic/1.jpg",
							username: "昵称",
							isguanzhu: false,
							title: "我是标题",
							type: "img", //img:图文 video: 视频
							titlepic: "../../static/demo/datapic/11.jpg",
							infoNum: {
								index: 1, //0 - 没有操作, 1 - 顶, 2 - 踩
								dingNum: 11,
								caiNum: 12,
							},
							commentNum: 12,
							shareNum: 123
						}, {
							userpic: "../../static/demo/userpic/1.jpg",
							username: "昵称",
							sex: 1, //0-男 1-女
							age: 25,
							isguanzhu: true,
							title: "我是标题",
							type: "video", //img:图文 video: 视频
							titlepic: "../../static/demo/datapic/11.jpg",
							playNum: "20w",
							long: "2:47",
							infoNum: {
								index: 2, //0 - 没有操作, 1 - 顶, 2 - 踩
								dingNum: 1,
								caiNum: 14,
							},
							commentNum: 12,
							shareNum: 123
						},
						{
							userpic: "../../static/demo/userpic/1.jpg",
							username: "昵称",
							sex: 0, //0-男 1-女
							age: 25,
							isguanzhu: true,
							title: "我是标题",
							type: "share", //img:图文 video: 视频
							titlepic: "../../static/demo/datapic/11.jpg",
							shareTitle: "我是分享标题",
							path: "深圳 龙岗",
							playNum: "20w",
							long: "2:47",
							commentNum: 12,
							shareNum: 123,
							goodNum: 20
						}
					]
				},
				topic: {
					swiper: [{
							src: "../../static/demo/banner1.jpg"
						},
						{
							src: "../../static/demo/banner1.jpg"
						},
						{
							src: "../../static/demo/banner1.jpg"
						}
					],
					nav:[
						{name:"最新"},
						{name:"游戏"},
						{name:"打卡"},
						{name:"故事"},
						{name:"喜爱"},
						{name:"最新"},
					],
					list:[
						{
							titlepic:"../../static/demo/topicpic/1.jpeg",
							title:"话题名称",
							desc:"我是话题描述",
							totalnum:50,
							todaynum:10
						},
						{
							titlepic:"../../static/demo/topicpic/2.jpeg",
							title:"话题名称",
							desc:"我是话题描述我是话题描是话题描述我",
							totalnum:50,
							todaynum:10
						},{
							titlepic:"../../static/demo/topicpic/3.jpeg",
							title:"话题名称",
							desc:"我是话题描述",
							totalnum:50,
							todaynum:10
						},{
							titlepic:"../../static/demo/topicpic/4.jpeg",
							title:"话题名称",
							desc:"我是话题描述",
							totalnum:50,
							todaynum:10
						}
					]
				}
			}
		},
		onLoad() {
			uni.getSystemInfo({
				success: (res) => {
					let height = res.windowHeight - uni.upx2px(100);
					// console.log(height);
					this.swiperHeight = height;
				}
			})
		},
		methods: {
			//tabbar点击事件
			tabtap(index) {
				this.tabIndex = index;
			},
			openAdd() {
				uni.navigateTo({
					url: "../add-input/add-input"
				})
			}, //swiper滑动事件
			swiperChange(e) {
				// console.log(JSON.stringify(e.detail));
				this.tabIndex = e.detail.current;
			},
			loadmore() {
				if (this.guanzhu.loadtext != "上拉加载更多") {
					return;
				}
				this.guanzhu.loadtext = "加载中";
				setTimeout(() => {
					//获取完成
					let obj = {
						userpic: "../../static/demo/userpic/12.jpg",
						username: "昵称",
						isguanzhu: false,
						title: "我是标题",
						type: "text", //img:图文 video: 视频
						titlepic: "",
						infoNum: {
							index: 1, //0 - 没有操作, 1 - 顶, 2 - 踩
							dingNum: 11,
							caiNum: 12,
						},
						commentNum: 12,
						shareNum: 123
					};
					this.guanzhu.list.push(obj);
					this.guanzhu.loadtext = "上拉加载更多";
				}, 1000)
			}
		}
	}
</script>

<style>
	.search-input {
		/* border: 1upx solid; */
		padding: 20upx;
	}

	.search-input>input {
		/* border: 1upx solid; */
		background-color: #F4F4F4;
		border-radius: 10upx;
	}

	.topic-search {
		font-size: 25upx;
	}


	.topic-swiper {
		padding: 0 20upx 20upx 20upx;
	}

	.topic-swiper image {
		width: 100%;
		border-radius: 5upx;
	}

	.topic-new {
		padding: 20upx;
	}
	
	.topic-new>view:first-child{
		padding-bottom: 5upx;
		font-size: 32upx;
	}

</style>
